package com.zx.ishopping.config;

import com.zx.ishopping.interceptors.LoginInterceptors;
import com.zx.ishopping.json.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.*;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.List;

/**
 * 注册拦截器
 * 作者 祝鑫
 * 时间 2025/6/24
 */
@Slf4j
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurationSupport {

    @Autowired
    private LoginInterceptors loginInterceptors;



    @Override
    public void addInterceptors(InterceptorRegistry  registry){
        registry.addInterceptor(loginInterceptors)
                //不拦截的路径
                .excludePathPatterns(
                        "/common/user/login",
                        "/user/user/userRegister",
                        "/user/user/getCaptcha",
                        "/user/user/chackCaptcha",
                        "/user/user/forgetPassword"
                        
                );
    }


    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        log.info("拓展消息转换器");
        //创建一个消息转换器对象
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        //需要为消息转换器设置一个对象转换器，对象转换器可以将Java对象序列化为Json数据
        converter.setObjectMapper(new JacksonObjectMapper());
        //将自己的消息转换器放入到容器中
        converters.add(0,converter);
    }


}
